﻿ //===============================RuinAlgorithm.cs==============================\\
//===Bart Steijlen======\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace Team2_Vision
{
    class RuinLines : VisionAlgorithm
    {
        public RuinLines(String name) : base(name) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage, int intensity)
        {

            Random random = new Random();
            Bitmap returnImage = new Bitmap(sourceImage);


            
            int randomx, randomy, directionx, directiony;
            Color pixel;
            for (int i = 0; i < intensity; i++)
            {
                
                randomx = random.Next(0, sourceImage.Width);
                randomy = random.Next(0, sourceImage.Height);
     
                pixel = sourceImage.GetPixel(randomx,randomy);

                directionx = random.Next(-1, 2);
                directiony = random.Next(-1, 2);
                for (int j = 0; j < intensity; j++)
                {
                    try
                    {
                        randomx = randomx + directionx;
                        randomy = randomy + directiony;
                        //array2[(randomy * sourceImage.Width + randomx) * 3] = (byte)pixelred;
                        //array2[(randomy * sourceImage.Width + randomx) * 3 + 1] = (byte)pixelgreen;
                        //array2[(randomy * sourceImage.Width + randomx) * 3 + 2] = (byte)pixelblue;
                        returnImage.SetPixel(randomx, randomy, pixel);
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
            }

            //Marshal.Copy(array2, 0, adressreturn, arraySize);
            //returnImage.UnlockBits(returnImageData);
            //sourceImage.UnlockBits(sourceImageData);
            return returnImage;
        }
    }
}